﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using TierApplication;
using System.Web.Security;

public partial class ForeProgram_Shared_MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AccountInfo"] == null)
        {
            FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();
            Response.Clear();
            Response.Write("<script defer>window.alert('您没有权限进入本页或当前登录用户已过期！\\n请重新登录或与管理员联系！');parent.location='Login.aspx';</script>");
            Response.End();
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["Bandwidth"] != null)
            {
                ViewState["type"] = "Bandwidth";
                ViewState["cond"] = Request.QueryString["Bandwidth"];
            }
            if (Request.QueryString["LifeTime"] != null)
            {
                ViewState["type"] = "LifeTime";
                ViewState["cond"] = Request.QueryString["LifeTime"];
            }
            if (Request.QueryString["CategoryId"] != null)
            {
                ViewState["type"] = "CategoryId";
                ViewState["cond"] = Request.QueryString["CategoryId"];
            }
            //LoadMenu();
            LoadLeftMenu();
            //LoadProduct();

        }
    }

    #region 加载左部菜单
    /// <summary>
    /// 加载左部菜单
    /// </summary>
    private void LoadLeftMenu()
    {
        StringBuilder sb = new StringBuilder("");
        P_DDCODE code = new P_DDCODE();
        DataSet listBand = code.GetList(" ddtype='Bandwidth'");
        if (listBand != null && listBand.Tables.Count != 0 && listBand.Tables[0].Rows.Count != 0)
        {
            if (ViewState["type"] == null || (ViewState["type"] != null && ViewState["type"] == "Bandwidth"))
            {
                sb.Append("<dl class=\"\">");
            }
            else
            {
                sb.Append("<dl class=\"list_sort_close\">");
            }
            sb.Append("<dt class='title_zhumai'><a id='proClass_Band' href=\"javascript:showProClass('Band');\">");
            sb.Append(@"带宽<em class='jian'></em></a> </dt>");
            sb.Append(@"<dd>");
            sb.Append("<ul class=\"list_sort\">");

            for (int i = 0; i < listBand.Tables[0].Rows.Count; i++)
            {
                string Key = "Bandwidth_" + listBand.Tables[0].Rows[i]["codeid"].ToString();
                sb.Append("<li class=\"on_dian\" style=\"clear: both\">");
                sb.Append("<h5 class=\"title_sort\">");
                sb.Append("<span class=\"fd\"></span>");
                sb.Append("<a href='product.aspx?Bandwidth=" + listBand.Tables[0].Rows[i]["codeid"].ToString() + "'  title=\"" + listBand.Tables[0].Rows[i]["codename"].ToString() + "\"><strong>" + listBand.Tables[0].Rows[i]["codename"].ToString() + "</strong></a>");
                sb.Append("</h5>");
                sb.Append(@"</li>");
            }
            sb.Append(@"</ul>");
            sb.Append(@"</dl>");
        }
        DataSet listTime = code.GetList(" ddtype='LifeTime'");
        if (listTime != null && listTime.Tables.Count != 0 && listTime.Tables[0].Rows.Count != 0)
        {
            if ((ViewState["type"] != null && ViewState["type"] == "LifeTime"))
            {
                sb.Append("<dl class=\"\">");
            }
            else
            {
                sb.Append("<dl class=\"list_sort_close\">");
            }
            //sb.Append("<dl class=\"list_sort_close\">");
            sb.Append("<dt class='title_zhumai'><a id='proClass_Time' href=\"javascript:showProClass('Time');\">");
            sb.Append(@"使用期限<em class='jian'></em></a> </dt>");
            sb.Append(@"<dd>");
            sb.Append("<ul class=\"list_sort\">");

            for (int i = 0; i < listTime.Tables[0].Rows.Count; i++)
            {
                string Key = "LifeTime_" + listTime.Tables[0].Rows[i]["codeid"].ToString();
                sb.Append("<li class=\"on_dian\" style=\"clear: both\">");
                sb.Append("<h5 class=\"title_sort\">");
                sb.Append("<span class=\"fd\"></span>");
                sb.Append("<a href='product.aspx?LifeTime=" + listTime.Tables[0].Rows[i]["codeid"].ToString() + "' title=\"" + listTime.Tables[0].Rows[i]["codename"].ToString() + "\"><strong>" + listTime.Tables[0].Rows[i]["codename"].ToString() + "</strong></a>");
                sb.Append("</h5>");
                sb.Append(@"</li>");
            }
            sb.Append(@"</ul>");
            sb.Append(@"</dl>");
        }
        DataSet listCategory = code.GetList(" ddtype='CategoryId'");
        if (listCategory != null && listCategory.Tables.Count != 0 && listCategory.Tables[0].Rows.Count != 0)
        {
            if ((ViewState["type"] != null && ViewState["type"] == "CategoryId"))
            {
                sb.Append("<dl class=\"\">");
            }
            else
            {
                sb.Append("<dl class=\"list_sort_close\">");
            }
            //sb.Append("<dl class=\"list_sort_close\">");
            sb.Append("<dt class='title_zhumai'><a id='proClass_Category' href=\"javascript:showProClass('Category');\">");
            sb.Append(@"商品类别<em class='jian'></em></a> </dt>");
            sb.Append(@"<dd>");
            sb.Append("<ul class=\"list_sort\">");

            for (int i = 0; i < listCategory.Tables[0].Rows.Count; i++)
            {
                string Key = "CategoryId_" + listCategory.Tables[0].Rows[i]["codeid"].ToString();
                sb.Append("<li class=\"on_dian\" style=\"clear: both\">");
                sb.Append("<h5 class=\"title_sort\">");
                sb.Append("<span class=\"fd\"></span>");
                sb.Append("<a href='product.aspx?CategoryId=" + listCategory.Tables[0].Rows[i]["codeid"].ToString() + "' title=\"" + listCategory.Tables[0].Rows[i]["codename"].ToString() + "\"><strong>" + listCategory.Tables[0].Rows[i]["codename"].ToString() + "</strong></a>");
                sb.Append("</h5>");
                sb.Append(@"</li>");
            }
            sb.Append(@"</ul>");
            sb.Append(@"</dl>");
        }

        shop_class_con.InnerHtml = sb.ToString();
    }
    #endregion
}
